package com.ly.springsolrtest.springsolr.config;

import com.ly.springsolrtest.springsolr.bo.Book;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

/**
 * Description: springsolr
 * <p>
 * Created by linweijian on 2018/5/24 13:35
 */
@Configuration
public class BookConvert {
    @Bean
    public Converter<String, Book> bookConverter() {
        return new Converter<String, Book>() {
            @Override
            public Book convert(String s) {
                if (StringUtils.isNotEmpty(s)) {
                    String[] book = s.split("-");
                    Book b = new Book();
                    b.setBookName(book[0]);
                    b.setAuthor(book[1]);
                    return b;
                }
                return null;
            }
        };
    }

}
